package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import pojo.Car;

/**
 * @author 24270
 */
@Controller
public class HelloController{

    @RequestMapping("/")
    public ModelAndView index() {
        ModelAndView mav = new ModelAndView("index");
        mav.addObject("message", "Hello Spring MVC");
        return mav;
    }

    @RequestMapping("/hello")
    public ModelAndView handleRequest() {
        ModelAndView mav = new ModelAndView("index");
        mav.addObject("message", "Hello Spring MVC");
        return mav;
    }

    @RequestMapping("/login")
    public ModelAndView login() {
        return new ModelAndView("form");
    }

    @RequestMapping("/param")
    public ModelAndView getParam(@RequestParam String userName, @RequestParam String password) {
        ModelAndView mav = new ModelAndView("showLoginInfo");
        if("admin".equals(userName) && "123".equals(password)) {
            mav.addObject("res", "登录成功");
        }else {
            mav.addObject("res", "登录失败！");
        }
        mav.addObject("name", userName);
        mav.addObject("password", password);
        return mav;
    }

}
